package com.example.aop.autoproxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class JdkHandler implements InvocationHandler {

    public Object target;

    public JdkHandler(Object target){
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        // 类似 Spring AOP 的环绕通知的实现

        System.out.println("前置通知");

        // 目标对象 -> 反射的方式进行调用
        Object invoke = method.invoke(target, args);

        System.out.println("后置通知");

        return invoke;
    }
}
